feat: migrate Qwen3 reasoning parser to token-level OutputRouter (closes #64)#97
Closed
Ai-chan-0411 wants to merge 1 commit intoraullenchai:mainfrom
Closed
feat: migrate Qwen3 reasoning parser to token-level OutputRouter (closes #64)#97Ai-chan-0411 wants to merge 1 commit intoraullenchai:mainfrom
Ai-chan-0411 wants to merge 1 commit intoraullenchai:mainfrom
Conversation
raullenchai#64) Add <think>/<\/think> token detection and routing to OutputRouter, replacing fragile regex-based text matching with token-level state machine transitions. Supports explicit, implicit, and no-tag scenarios. - Detect Qwen3/DeepSeek tokenizers via <think> + </think> vocab entries - Route tokens between <think>/<\/think> to REASONING channel - 9 new tests covering all Qwen3 scenarios (31 total, all passing)
Author
|
Closing as maintainer has not reviewed after 168h. Thank you for the opportunity! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #64
Summary
Migrate Qwen3's
<think>/</think>reasoning parser from regex-basedBaseThinkingReasoningParserto the token-levelOutputRouterstate machine.Changes
vllm_mlx/output_router.py<think>/</think>token handling infeed()—think_startenters THINKING state,think_endswitches to CONTENTfrom_tokenizer()via<think>+</think>vocabulary entriesthink_start/think_endfields (added for future migration) — now wired uptests/test_output_router.pyqwen3_routerfixtureTestQwen3ThinkRoutingclass with 9 tests:<think>enters THINKING state</think>switches to CONTENT state</think>routed to CONTENT channel<think>reasoning</think>contentsequence viafeed_sequence()<think>, only</think>) handledtest_qwen3_detectedinTestFromTokenizer31 tests total, all passing.
Design
Follows the same pattern as the existing Gemma 4 implementation — token-level state machine with no text-level regex matching. This eliminates partial-token split issues that affect the current regex-based parser.
The detection uses
<think>+</think>in the tokenizer vocabulary, which covers both Qwen3 and DeepSeek R1 model families.